home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2461 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++,comp.lang.c
  4. Subject: Re: Hungarian notation
  5. Date: Wed, 17 Jan 1996 19:55:54 GMT
  6. Organization: Netcom
  7. Message-ID: <30fd5306.3171520@nntp.ix.netcom.com>
  8. References: <4dhkae$an9@blackice.winternet.com> <821890870snz@genesis.demon.co.uk>
  9. NNTP-Posting-Host: ix-dc15-24.ix.netcom.com
  10. X-NETCOM-Date: Wed Jan 17 11:55:54 AM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
  14.  
  15. |>In article <4dhkae$an9@blackice.winternet.com>
  16. |>           jdege@winternet.com "Jeff Dege" writes:
  17. |>
  18. |>>    Generally speaking, when I use printf(), et al., with integer
  19. types
  20. |>>of uncertain or unknown size, I explicitly cast.  i.e.:
  21. |>>
  22. |>>printf("The current epoch is %ld\n", (long) time(NULL));
  23. |>>
  24. |>>    This is, as far as I know, the only safe way to printf() a
  25. time_t, 
  26. |>>size_t, etc.
  27. |>
  28. |>There is no guarantee that time_t is an integer. To print it safely
  29. you
  30. |>should cast it to long double. size_t is guaranteed to be an
  31. unsigned
  32. |>integer so it should be cast to unsigned long for printing.
  33.  
  34. I'm sure Lawrence is aware of this, but it's worth noting that while
  35. casting to long double is almost certainly safe in that it will not
  36. cause damage, it may not print out anything useful.  It's possible
  37. that time_t is an integral type that cannot be represented exactly as
  38. a long double and the least significant bits, that are lost in the
  39. conversion, may be significant.
  40.  
  41. There is one possibility that makes the cast to long double
  42. potentially dangerous according to the standard.  There is no
  43. guarantee in the standard that all possible values of an integral type
  44. can be converted to long double.  Such an implementation would be
  45. pretty wierd, and I doubt if we'll ever see one.
  46.  
  47.  
  48. Michael M Rubenstein
  49.